import Qs from 'qs'
import { request } from '@/utils/request'
import type { IResponse } from '.'
import { type RequestTableResult } from '@/hook/useTable'
import { ROLE_TYPE,PREFIX_CHAT } from '@/const'
import { type GuideItem } from '@/api/type'
// 获取审核列表
export function apiAuditList(params?: AuditListParams) {
  return request({
    method: 'get',
    url: `${PREFIX_CHAT}/copilotApply/admin/list`,
    params
  })
}

/**
 * 试用申请审核通过并创建团队
 * @param {TeamForm} data
 * @returns
 */
export function apiAuditTeamAdd(data: TeamForm) {
  return request({
    method: 'post',
    url: `${PREFIX_CHAT}/copilotApply/admin/auditSuccess`,
    data
  })
}

/**
 * 拒绝试用
 * @param params
 * @returns
 */
export function apiAuditReject(params: { applyId: string }) {
  return request({
    method: 'get',
    url: `${PREFIX_CHAT}/copilotApply/admin/reject`,
    params
  })
}

// 获取团队列表
export function apiTeamManageList(data: TeamManageListParams): Promise<RequestTableResult> {
  return request({
    method: 'post',
    url: `${PREFIX_CHAT}/copilotTeam/admin/list`,
    data
  })
}

// 编辑团队配置
export function apiTeamManageUpdate(data: TeamForm) {
  return request({
    method: 'post',
    url: `${PREFIX_CHAT}/copilotTeam/admin/update`,
    data
  })
}

// 编辑团队名称
export function apiUpdateTeamName(data: { teamId: string; teamName: string }) {
  return request({
    method: 'post',
    url: `${PREFIX_CHAT}/copilotTeam/updateTeam`,
    data: Qs.stringify(data)
  })
}

// 移交团队
export function apiTransferTeam(data: { teamCustomerId: string }) {
  return request({
    method: 'post',
    url: `${PREFIX_CHAT}/copilotTeam/transfer`,
    data: Qs.stringify(data)
  })
}

// 将成员移出团队
export function apiRemoveMember(data: { teamCustomerId: string }) {
  return request({
    method: 'post',
    url: `${PREFIX_CHAT}/copilotTeam/removeCustomer`,
    data: Qs.stringify(data)
  })
}

// 团队成员更改角色
export function apiChangeRole(data: { roleType: ROLE_TYPE; teamCustomerId: string }) {
  return request({
    method: 'post',
    url: `${PREFIX_CHAT}/copilotTeam/changeRole`,
    data: Qs.stringify(data)
  })
}

// 创建团队
export function apiCreateTeam(data: TeamForm) {
  return request({
    method: 'post',
    url: `${PREFIX_CHAT}/copilotTeam/admin/insert`,
    data
  })
}

// 启用、禁用团队
export function apiUpdateTeamStatus(data: { teamId: string; usedStatus: number }) {
  return request({
    method: 'post',
    url: `${PREFIX_CHAT}/copilotTeam/admin/updateStatus`,
    data: Qs.stringify(data)
  })
}

// 获取团队成员列表
export function apiTeamMemberList(params: TeamMemberTable): Promise<RequestTableResult> {
  return request({
    method: 'get',
    url: `${PREFIX_CHAT}/copilotTeam/customerList`,
    params
  })
}

// 获取团队详情
export function apiTeamInfo(params: { teamId: string }) {
  return request({
    method: 'get',
    url: `${PREFIX_CHAT}/copilotTeam/info`,
    params
  })
}

// 生成邀请信息
export function apiGenerateInviteInfo(params: { teamId: string }) {
  return request({
    method: 'get',
    url: `${PREFIX_CHAT}/copilotInviteInfo/createInviteInfo`,
    params
  })
}

/**
 * 欢迎语详情
 * @param type  类型 1检索对话欢迎语 2文档解读欢迎语
 * @returns 
 */
export function apiCopilotWelcome(params: { type: number }) {
  return request({
    method: 'get',
    url: `${PREFIX_CHAT}/copilotWelcome/info`,
    params
  })
}

/**
 * 获取首页引导欢迎语列表
 * @param type  类型 1检索对话欢迎语 2文档解读欢迎语
 * @returns 
 */
export function apiCopilotWelcomeAdminList(params: { type: number,pageNum:1,pageSize:8  }) {
  return request({
    method: 'get',
    url: `${PREFIX_CHAT}/copilotWelcome/admin/list`,
    params
  })
}

/**
 * 后台编辑欢迎语
 * @param content 内容
 * @param type 类型 1检索对话欢迎语 2文档解读欢迎语
 * @returns 
 */
export function apiUpdateWelcome(data: GuideItem) {
  return request({
    method: 'post',
    url: `${PREFIX_CHAT}/copilotWelcome/admin/save-or-update`,
    data
  })
}

/**
 * 后台编辑欢迎语
 * @param content 内容
 * @param type 类型 1检索对话欢迎语 2文档解读欢迎语
 * @returns 
 */
export function apiRemoveWelcome(data: GuideItem) {
  return request({
    method: 'get',
    url: `${PREFIX_CHAT}/copilotWelcome/admin/remove/`+ data.id,
  })
}


export interface AuditListParams {
  auditStatus?: number | string
  beginTime?: string
  endTime?: string
  entName?: string
  pageNum: number
  pageSize: number
  phone?: string
}

export interface TeamForm {
  phone: string // 团队所有者手机号
  teamName: string // 团队名称
  entName: string // 企业名称
  peopleLimit: number // 人数上限
  expiredTime: string // 失效时间
  authorityStatus: number // 内部文档权限：0:无 1:有
  applyId?: string // 试用申请id
  id?: string // 试用申请id
  formulaAuthority: number // 公式权限：0:无 1:有
}

export interface TeamManageListParams {
  teamName?: number | string
  entName?: string
  phone?: string
  loginTimeBegin?: string
  loginTimeEnd?: string
  expiredTimeBegin?: string
  expiredTimeEnd?: string
  pageNum: number
  pageSize: number
}

interface IPageParam {
  pageSize: number
  pageNum: number
}

interface TeamMemberTable extends IPageParam {
  teamId: string
}

export interface TeamInfo {
  authorityStatus: number
  customerName: string
  createdTime: string
  entName: string
  expiredTime: string
  id: string
  lastedLoginTime: string
  peopleLimit: string
  phone: string
  teamName: string
  usedStatus: number
  formulaAuthority: number // 公式权限：0:无 1:有
}
